<template>
  <div class="city">
    <city-header></city-header>
    <city-search></city-search>
    <city-list
      :cities="cities"
      :hotCities="hotCities"
      :letter="letter">
    </city-list>
    <city-alphabet :cities="cities" @change="handleLetter"></city-alphabet>
  </div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  mounted () {
    this.getCityInfo()
  },
  methods: {
    // 获取城市信息
    getCityInfo () {
      axios.get('/api/city.json').then(res => {
        console.log(res)
        if (res.data.ret && res.data.data) {
          this.cities = res.data.data.cities
          this.hotCities = res.data.data.hotCities
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 获取alphabet子组件发射过来的字母
    handleLetter (letter) {
      this.letter = letter
    }
  }
}
</script>

<style lang="stylus" scoped>
.city {

}
</style>
